package com.cqw.commontest.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-02 11:07
 * @Description: 统计
 * 1、计数：count
 * 2、平均值：averagingInt/averagingLong/averagingDouble
 * 3、最值：maxBy/minBy
 * 4、求和：summingInt/summingLong/summingDouble
 * 5、统计以上所有（会返回一个对象）：summarizingInt,summarizingLong,summarizingDouble
 */
public class StreamTest6 {


    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("张三", 1000, 21, "男", "上海"));
        personList.add(new Person("李四", 2000, 25, "女", "安徽"));
        personList.add(new Person("王五", 2200, 36, "男", "杭州"));
        personList.add(new Person("赵六", 1400, 25, "女", "南京"));
        personList.add(new Person("曹七", 3000, 12, "男", "北京"));
        personList.add(new Person("Lily", 5000, 42, "女", "上海"));

        //统计员工总数，平均工资，工资总额，最高工资
        long count = personList.stream().count();
        Long collect = personList.stream().collect(Collectors.counting());

        //求平均工资
        Double collect1 = personList.stream().collect(Collectors.averagingInt(Person::getSalary));




    }


}
